package cz.khfotbal.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cz.khfotbal.dao.DelegatDao;
import cz.khfotbal.domain.Delegat;

@Repository
@Transactional
public class DelegatDaoImpl implements DelegatDao {

	@Autowired
	private SessionFactory sessionFactory;

	private Session session;

	public List<Delegat> findAll() {
		session = sessionFactory.getCurrentSession();
		List<Delegat> list = session.createQuery("from Delegat").list();
		return list;
	}

	public void update(Delegat referee) {
		session = sessionFactory.getCurrentSession();
		session.update(referee);
	}

	public void delete(Delegat referee) {
		session = sessionFactory.getCurrentSession();
		session.delete(referee);
	}

	public void save(Delegat referee) {
		session = sessionFactory.getCurrentSession();
		session.saveOrUpdate(referee);
	}

}
